<template>
  <div class="app-container">
    <el-form :inline="true" ref="form" :model="queryParams" class="demo-form-inline">
      
      
      <el-form-item label="昵称" prop="username">
        <el-input v-model="queryParams.username" placeholder="昵称" />
      </el-form-item>
     
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button type="primary" @click="reset">重置</el-button>
      </el-form-item>
    </el-form>
    <el-button type="primary" @click="addAdminUser" style="margin-bottom: 15px;">新增</el-button>

    <el-table v-loading="listLoading" :data="list" element-loading-text="Loading" border fit highlight-current-row>
      <el-table-column align="center" label="id" prop="id" width="95" />
      <el-table-column label="昵称" align="center" prop="username" />
      <el-table-column label="区号" align="center" prop="countryNo" />
      <el-table-column label="手机号" align="center" prop="mobile" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center" width="350">
        <template slot-scope="scope">
          <el-button type="text" @click="handleShowInfo(scope.row)">查看</el-button>
          <el-button type="text" style="color: red;" @click="handleHistory(scope.row)">删除</el-button>
          <el-button type="text" @click="handleEdit(scope.row)">修改</el-button>
          <el-button type="text" @click="handleReset(scope.row)">重置密码</el-button>

          <!-- <el-button type="text" @click="handleC(scope.row)">团队收益</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination :current-page.sync="queryParams.pageNum" :page-sizes="[10, 20, 30, 40]"
        :page-size.sync="queryParams.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"
        @size-change="fetchData" @current-change="fetchData" />
    </div>
    <showInfo ref="showInfo" />
    <add ref="add" />
    <addC ref="addC" />

  </div>
</template>

<script>
import showInfo from './showInfo.vue'
import add from './add.vue'
import addC from './addC.vue'

import { adminUserList, saveOrUpdate,adminUserDel } from '@/api/table'
export default {
  components: {
    showInfo,
    add,
    addC,

  },
  data() {
    return {
      list: null,
      listLoading: true,
      total: 0,
      timer: null,
      statusOptions: [
        { label: '正常', value: '1' },
        { label: '禁用', value: '0' }

      ],
      queryParams: {
        username: '',
        pageNum: 1,
        pageSize: 10,
        
      }
    }
  },
  created() {
    this.fetchData()
  },
  destroyed() {

  },
  methods: {

    handleHistory(record) {
      this.$confirm('此操作将删除该用户, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        const res = await adminUserDel({id: record.id})
        this.fetchData()
      })
    },
    

    fetchData() {
      this.listLoading = true
      adminUserList(this.queryParams).then(response => {
      
        this.list = response.data.records
        this.listLoading = false
        this.total = response.data.total
      })
    },
    handleShowInfo(e) {
      this.$refs.showInfo.show(e)
    },
    onSubmit() {
      this.queryParams.pageNum = 1
      this.fetchData()
    },
    reset() {
      this.queryParams = {
        username: '',
      
      }
      this.fetchData()
    },
    addAdminUser() {
      this.$refs.add.show()
    },
    handleEdit(e) {
      this.$refs.add.edit(e)
    },
    handleReset(e){
      this.$refs.addC.show(e)

    }

  }
}
</script>
